// pages/trip/trip.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        currentTab: 0,
        clientHeight: 0,
        navHeight: 0,
        navHeightRaw: 0
    },


    addTrip: function (e) {
        wx.navigateTo({
            url: '/pages/setDate/setDate',
        })
    },


    switchNav: function (e) {
        var index = e.target.id
        this.setData({
            currentTab: index
        })
    },
    /* nav绑定页面 */
    change: function (e) {
        var index = e.detail.current;
        this.setData({
            currentTab: index
        })
    },

    getRpx: function (e) {
        var winWidth = wx.getSystemInfoSync().windowWidth;
        return e * 750 / winWidth;
    },

    getPx: function (e) {
        var winWidth = wx.getSystemInfoSync().windowWidth;
        return e / (750 / winWidth);
    },

    getNavHeight: async function () {
        let getMenuButton = await wx.getMenuButtonBoundingClientRect();
        console.log(getMenuButton, 'getMenuButton')
        this.setData({
            navHeight: getMenuButton.bottom + this.getPx(90) + this.getPx(28),
            navHeightRaw: getMenuButton.bottom
        })
        /* 获取窗口高度 */
        var that = this
        wx.getSystemInfo({
            success: function (res) {
                that.setData({
                    clientHeight: res.windowHeight,
                });
            }
        })
    },

    showTripDetail: function(e) {
        console.log(e.currentTarget.dataset.tripid)
        wx.navigateTo({
          url: '/pages/tripDetail/tripDetail?id=' + e.currentTarget.dataset.tripid,
        })
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.getNavHeight()
        wx.showLoading({
            title: '加载中',
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: async function () {
        var that = this
        wx.cloud.callFunction({
            name: 'getMyTrip'
        }).then(res => {
            wx.hideLoading({
                success: (res) => {},
            })
            console.log(res.result)
            that.setData({
                myTripData: res.result
            })
        })
        //
        wx.cloud.callFunction({
            name: 'getPubTrip'
        }).then(res => {
            console.log(res.result)
            that.setData({
                pubTripData: res.result
            })
        })


    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})